package world.liquor.dao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
import org.springframework.stereotype.Repository;

import world.liquor.domain.BeerAssessment;

@Repository
public class BeerAssessmentDAOImpl implements BeerAssessmentDAO{
	
	@Autowired
	private SqlMapClientTemplate sqlMap;
	public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMap){
		this.sqlMap = sqlMap;
	}
	
	//평가 등록
	public void insertBeerAssessment(BeerAssessment assess) throws SQLException{
		sqlMap.insert("insertBeerAssessment", assess);
	}
	
	//평가 삭제: 평가아이디
	public int deleteBeerAssessment(int beer_assessment_id) throws SQLException{
		return sqlMap.delete("deleteBeerAssessment", beer_assessment_id);
	}
	
	//평가 업데이트: 평가아이디
	public int updateBeerAssessment(BeerAssessment assessment) throws SQLException{
		return sqlMap.update("updateBeerAssessment", assessment);
	}
	
	//조회: by 평가ID
	public BeerAssessment selectBeerAssessmentById(int beer_assessment_id) throws SQLException{
		return (BeerAssessment)sqlMap.queryForObject("selectBeerAssessmentById", beer_assessment_id);
	}
	//조회: by 평가한 회원id, 평가된 맥주id
	public BeerAssessment selectBeerAssessmentByMemberAndBeerId(String member_id, String beer_info_id) throws SQLException{
		HashMap map = new HashMap();
		map.put("memberId", member_id);
		map.put("beerInfoId", beer_info_id);
		return (BeerAssessment)sqlMap.queryForObject("selectBeerAssessmentByMemberIdAndBeerInfoId", map);
	}
	
	//조회: by 평가한 회원id
	public ArrayList<BeerAssessment> selectBeerAssessmentByMemberId(String member_id) throws SQLException{
		return (ArrayList<BeerAssessment>)sqlMap.queryForList("selectBeerAssessmentByMemberId", member_id);
	}
	
	//조회: by 평가된 맥주id
	public ArrayList<BeerAssessment> selectBeerAssessmentByBeerInfoId(String beer_info_id) throws SQLException{
		return (ArrayList<BeerAssessment>)sqlMap.queryForList("selectBeerAssessmentByBeerInfoId", beer_info_id);
	}
	
	//조회: by 평가점수
	public ArrayList<BeerAssessment> selectBeerAssessmentByAssessment(int assessment) throws SQLException{
		return (ArrayList<BeerAssessment>)sqlMap.queryForList("selectBeerAssessmentByAssessment", assessment);
	}
	
	//조회 : 모든 평가 조회
	public ArrayList<BeerAssessment> selectAllBeerAssessment() throws SQLException{
		return (ArrayList<BeerAssessment>)sqlMap.queryForList("selectAllBeerAssessment");
	}
	
}
